import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ProjectService {

  constructor(
    private http: HttpClient
  ) { }

  httpOptions = {
    //headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' })
    //headers: new HttpHeaders({ 'Content-Type': 'application/json' })
    headers: new HttpHeaders({ 'Content-Type': 'application/form-data' })

  };

  getStockById(id: any): Observable<any> {
    var formData = new FormData();
    formData.append("id", id);
    const url = 'http://101.35.86.65:5000/getStockById';
    return this.http.post(url, formData)
  }

  addStock(nums: string[], stockIds: string[], userId: string): Observable<any> {
    var formData = new FormData();
    for (let i = 0; i < nums.length; i++) {
      formData.append("nums", nums[i]);
    }
    for (let j = 0; j < stockIds.length; j++) {
      formData.append("stockIds", stockIds[j]);
    }
    formData.append("userId", userId);
    const url = 'http://101.35.86.65:5000/addStock';
    return this.http.post(url, formData)
  }
}